#coding:utf-8
'''
Created on 2017-06-12

@author: sandy
'''

import os
import json
from pycommon import RemoteManager
from pycommon import Utils

class Config(object):
    
    def __init__(self):
        self.rundir = os.path.dirname(__file__)
        self.index = 1
        self.upload_dir = u''
        self.hot_update = u''
        self.hot_servers = []

        self.redisdb_ip =u"192.168.1.100"
        self.redisdb_port=6379
        self.redisdb_db=0
        self.redisdb_passwd=u""
        self.redisdb_linkcount = 0

    
    #加载同目录文件夹下的配置文件
    def loadFromFile(self):
        cf = json.load(file(os.path.join(self.rundir,"serverconfig.json")), encoding='utf-8')
        self.loadFromJson(cf)
       
    def loadFromJson(self, cf):
        self.index = cf.get("index")
        self.upload_dir = cf.get("upload_dir")
        self.hot_update = cf.get("hotupdate_dir")
        self.hot_servers = cf.get("hot_servers")
        dbstr = cf.get("redis_db")
        dbparams = dbstr.split(u',')
        self.redisdb_ip =dbparams[0]
        self.redisdb_port=int(dbparams[1])
        self.redisdb_db= int(dbparams[2])
        self.redisdb_passwd=dbparams[3] if dbparams[3]!="0" else None
        self.redisdb_linkcount = int(dbparams[4])
   
instance = Config()